package com.demo2do.fms.entity.vehicle.tractor;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.fms.entity.vehicle.ModifiedStatus;

/**
 *
 * @author Ark
 *
 */
@Entity
@Table(name = "FMS_TRACTOR_MODIFIED_VERSION")
public class TractorModifiedVersion {
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;
    
    /** 变更状态 */
    @Enumerated(EnumType.STRING)
    private ModifiedStatus status;
    
    /** 版本号 */
    private int versionSorting;
    
    /** 牵引车ID */
    private Long tractorId;
    
    /** 运输工具类型  */
    @Enumerated(EnumType.STRING)
    private TransMean transMean;
    
    /** 车辆类型（行驶证） */
    @Enumerated(EnumType.STRING)
    private TractorVehicleType vehicleType;
    
    /** 产证所有者 */
    private String floorLord;
    
    /** 车辆所属权 */
    @Enumerated(EnumType.STRING)
    private CarOwnership carOwnership;
    
    /** 车头45度照片 */
    private String vehiclePhoto;
    
    /** 购车合同 */
    private String vehicleContact;
    
    /** VIN码 */
    @Column(name = "VIN")
    private String vincode;
    
    /** 品牌 */
    private String brand;
    
    /** 马力 */
    private BigDecimal horsepower;
    
    /** 发证时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date issuingTime;
    
    /** 注册日期 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date registrationTime;

    /** 年检有效期至 - 年月 */
    @DateTimeFormat(pattern = "yyyy-MM")
    private Date annualInspectionDate;
    
    /** 轴数 */
    private BigDecimal axles;
    
    /** 装载量 */
    private BigDecimal trainload;
    
    /** 行驶证 */
    private String drivingLicense;
    
    /** 行驶证副本及检验页扫描件 */
    private String drivingLicenseCopy;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public TractorModifiedVersion() {
    }

    /**
     * @param tractor
     * @param versionSorting
     */
    public TractorModifiedVersion(Tractor tractor, int versionSorting) {
        this.status = ModifiedStatus.AUDITING;
        this.tractorId = tractor.getId();
        this.versionSorting = versionSorting;
        this.disabled = false;
    }
    
    /**
     * VAM车辆变更申报
     * 
     * @param tractor
     * @param newTractor
     * @param versionSorting
     */
    public TractorModifiedVersion(Tractor tractor, Tractor newTractor, int versionSorting) {
        
        this.status = ModifiedStatus.AUDITING;
        this.tractorId = tractor.getId();
        this.versionSorting = versionSorting;
        
        this.floorLord = newTractor.getFloorLord();
        this.carOwnership = newTractor.getCarOwnership();
        this.vincode = newTractor.getVincode();
        this.brand = newTractor.getBrand();
        this.issuingTime = newTractor.getIssuingTime();
        this.horsepower = newTractor.getHorsepower();
        this.registrationTime = newTractor.getRegistrationTime();
        this.annualInspectionDate = newTractor.getAnnualInspectionDate();
        this.axles = newTractor.getAxles();
        this.trainload = newTractor.getTrainload();
        this.vehicleType = newTractor.getVehicleType();
        
        if (!StringUtils.equals(tractor.getDrivingLicense(), newTractor.getDrivingLicense())) {
            this.drivingLicense = newTractor.getDrivingLicense();
        }
        if (!StringUtils.equals(tractor.getDrivingLicenseCopy(), newTractor.getDrivingLicenseCopy())) {
            this.drivingLicenseCopy = newTractor.getDrivingLicenseCopy();
        }
        if (!StringUtils.equals(tractor.getVehiclePhoto(), newTractor.getVehiclePhoto())) {
            this.vehiclePhoto = newTractor.getVehiclePhoto();
        }
        if (!StringUtils.equals(tractor.getVehicleContact(), newTractor.getVehicleContact())) {
            this.vehicleContact = newTractor.getVehicleContact();
        }
        
        this.disabled = false;
        
    }

    /**
     * @return
     */
    public boolean requireTrailer() {
        return trainload == null || trainload.intValue() <= 0;
    }
    
    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the status
     */
    public ModifiedStatus getStatus() {
        return status;
    }

    /**
     * @return the versionSorting
     */
    public int getVersionSorting() {
        return versionSorting;
    }

    /**
     * @return the tractorId
     */
    public Long getTractorId() {
        return tractorId;
    }

    /**
     * @return the transMean
     */
    public TransMean getTransMean() {
        return transMean;
    }

    /**
     * @return the vehicleType
     */
    public TractorVehicleType getVehicleType() {
        return vehicleType;
    }

    /**
     * @return the floorLord
     */
    public String getFloorLord() {
        return floorLord;
    }

    /**
     * @return the carOwnership
     */
    public CarOwnership getCarOwnership() {
        return carOwnership;
    }

    /**
     * @return the vehiclePhoto
     */
    public String getVehiclePhoto() {
        return vehiclePhoto;
    }

    /**
     * @return the vehicleContact
     */
    public String getVehicleContact() {
        return vehicleContact;
    }

    /**
     * @return the vincode
     */
    public String getVincode() {
        return vincode;
    }

    /**
     * @return the brand
     */
    public String getBrand() {
        return brand;
    }

    /**
     * @return the horsepower
     */
    public BigDecimal getHorsepower() {
        return horsepower;
    }

    /**
     * @return the issuingTime
     */
    public Date getIssuingTime() {
        return issuingTime;
    }

    /**
     * @return the registrationTime
     */
    public Date getRegistrationTime() {
        return registrationTime;
    }

    /**
     * @return the annualInspectionDate
     */
    public Date getAnnualInspectionDate() {
        return annualInspectionDate;
    }

    /**
     * @return the axles
     */
    public BigDecimal getAxles() {
        return axles;
    }

    /**
     * @return the trainload
     */
    public BigDecimal getTrainload() {
        return trainload;
    }

    /**
     * @return the drivingLicense
     */
    public String getDrivingLicense() {
        return drivingLicense;
    }

    /**
     * @return the drivingLicenseCopy
     */
    public String getDrivingLicenseCopy() {
        return drivingLicenseCopy;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(ModifiedStatus status) {
        this.status = status;
    }

    /**
     * @param versionSorting the versionSorting to set
     */
    public void setVersionSorting(int versionSorting) {
        this.versionSorting = versionSorting;
    }

    /**
     * @param tractorId the tractorId to set
     */
    public void setTractorId(Long tractorId) {
        this.tractorId = tractorId;
    }

    /**
     * @param transMean the transMean to set
     */
    public void setTransMean(TransMean transMean) {
        this.transMean = transMean;
    }

    /**
     * @param vehicleType the vehicleType to set
     */
    public void setVehicleType(TractorVehicleType vehicleType) {
        this.vehicleType = vehicleType;
    }

    /**
     * @param floorLord the floorLord to set
     */
    public void setFloorLord(String floorLord) {
        this.floorLord = floorLord;
    }

    /**
     * @param carOwnership the carOwnership to set
     */
    public void setCarOwnership(CarOwnership carOwnership) {
        this.carOwnership = carOwnership;
    }

    /**
     * @param vehiclePhoto the vehiclePhoto to set
     */
    public void setVehiclePhoto(String vehiclePhoto) {
        this.vehiclePhoto = vehiclePhoto;
    }

    /**
     * @param vehicleContact the vehicleContact to set
     */
    public void setVehicleContact(String vehicleContact) {
        this.vehicleContact = vehicleContact;
    }

    /**
     * @param vincode the vincode to set
     */
    public void setVincode(String vincode) {
        this.vincode = vincode;
    }

    /**
     * @param brand the brand to set
     */
    public void setBrand(String brand) {
        this.brand = brand;
    }

    /**
     * @param horsepower the horsepower to set
     */
    public void setHorsepower(BigDecimal horsepower) {
        this.horsepower = horsepower;
    }

    /**
     * @param issuingTime the issuingTime to set
     */
    public void setIssuingTime(Date issuingTime) {
        this.issuingTime = issuingTime;
    }

    /**
     * @param registrationTime the registrationTime to set
     */
    public void setRegistrationTime(Date registrationTime) {
        this.registrationTime = registrationTime;
    }

    /**
     * @param annualInspectionDate the annualInspectionDate to set
     */
    public void setAnnualInspectionDate(Date annualInspectionDate) {
        this.annualInspectionDate = annualInspectionDate;
    }

    /**
     * @param axles the axles to set
     */
    public void setAxles(BigDecimal axles) {
        this.axles = axles;
    }

    /**
     * @param trainload the trainload to set
     */
    public void setTrainload(BigDecimal trainload) {
        this.trainload = trainload;
    }

    /**
     * @param drivingLicense the drivingLicense to set
     */
    public void setDrivingLicense(String drivingLicense) {
        this.drivingLicense = drivingLicense;
    }

    /**
     * @param drivingLicenseCopy the drivingLicenseCopy to set
     */
    public void setDrivingLicenseCopy(String drivingLicenseCopy) {
        this.drivingLicenseCopy = drivingLicenseCopy;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
    
}